package org.example.multiThreading.ThreadMethod;

public class MyThreadDaemon {
    public static void main(String[] args) {
        TestThreadDaemon daemon = new TestThreadDaemon("守护线程");
        //将此线程设置为守护线程
        daemon.setDaemon(true);
        //启动线程
        daemon.start();

        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }
}

class TestThreadDaemon extends Thread{

    public TestThreadDaemon(String name){
        super(name);
    }

    @Override
    public void run(){
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"-"+i);
            try {
                Thread.sleep(1000);
            }catch (Exception e){

            }
        }
    }
}
